package com.ruoyi.classai.utils.group;
import okhttp3.*;

import java.io.IOException;

public class OkHttpUtil {

    private static final OkHttpClient client = new OkHttpClient();

    public static String sendPostRequest(String url, String jsonBody) throws IOException {
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody requestBody = RequestBody.create(mediaType, jsonBody);

        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .addHeader("accept", "application/json")
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            return response.body().string();
        }
    }
}